﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Activities;
using VMware.Vim;

namespace VMWareActivities
{
    using Microsoft.TeamFoundation.Build.Client;

    [BuildActivity(HostEnvironmentOption.All)]
    public sealed class TakeSnapshotAcitvity : CodeActivity
    {
        /// <summary>
        /// Gets or sets the name of the snapshot.
        /// </summary>
        /// <value>The name of the snapshot.</value>
        [RequiredArgument]
        public InArgument<string> SnapshotName { get; set; }

        /// <summary>
        /// Gets or sets the snapshot description.
        /// </summary>
        /// <value>The snapshot description.</value>
        [RequiredArgument]
        public InArgument<string> SnapshotDescription { get; set; }

        /// <summary>
        /// Gets or sets the memory.
        /// </summary>
        /// <value>The memory.</value>
        [RequiredArgument]
        public InArgument<bool> Memory { get; set; }

        /// <summary>
        /// Gets or sets the quiesce.
        /// </summary>
        /// <value>The quiesce.</value>
        [RequiredArgument]
        public InArgument<bool> Quiesce { get; set; }

        /// <summary>
        /// Gets or sets the virtual machine.
        /// </summary>
        /// <value>The virtual machine.</value>
        [RequiredArgument]
        public InArgument<VirtualMachine> VirtualMachine { get; set; }

        /// <summary>
        /// When implemented in a derived class, performs the execution of the activity.
        /// </summary>
        /// <param name="context">The execution context under which the activity executes.</param>
        protected override void Execute(CodeActivityContext context)
        {
            string snapshotName = context.GetValue(this.SnapshotName);
            string snapshotDescription = context.GetValue(this.SnapshotDescription);
            bool memory = context.GetValue(this.Memory);
            bool quiesce = context.GetValue(this.Quiesce);
            VirtualMachine virtualMachine = context.GetValue(this.VirtualMachine);

            virtualMachine.CreateSnapshot(snapshotName, snapshotDescription, memory, quiesce);
        }
    }
}
